package com.ruoxi.controller;

import com.ruoxi.repository.UserRepository;
import com.ruoxi.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TestController {
    @Autowired
    private UserRepository userRepository;
//    private JdbcTemplate jdbcTemplate;
    @RequestMapping("/getUsers")
    public List<User> findAll(){
        return userRepository.findAll();
    }
    @RequestMapping("/register")
    public boolean register(@RequestParam("userId") String userId,
                            @RequestParam("userName") String userName,
                            @RequestParam("password") String password){
        try {
            userRepository.register(userId,userName,password);
            return true; //注册成功则返回true
        } catch (Exception e) {
            e.printStackTrace();
        }return false;
    }
    @RequestMapping("/login")
    public boolean login(@RequestParam("userId") String userId,
                         @RequestParam("password") String password){
        User user=null;
        user = userRepository.login(userId,password);
        //对比密码，相同则返回true，正常情况会加密解密，为求简单就不那么做了
        if(user.getPassword().equals(password))
            return true;
        return false;
    }

}
